package gui_classes;

import javax.swing.*;

import java.awt.*;
import java.awt.event.*;

/**
 * This class represents the login screen
 * @author SCIUUG Faults
 *
 */
public class LoginPanel extends DERPBase {
	private JTextField txtUsername;
	private JPasswordField passwordField;
	private String arr[];

	/**
	 * Create the panel.
	 */
	public LoginPanel() {
		setLayout(null);
		
		JButton btnLogin = new JButton("Login");
		btnLogin.setBounds(90, 217, 117, 25);
		btnLogin.addActionListener(new LoginListener());
		add(btnLogin);
		
		JButton btnRegister = new JButton("Register");
		btnRegister.setBounds(243, 217, 117, 25);
		btnRegister.addActionListener(new RegisterListener());
		add(btnRegister);
		
		arr = new String[2];
		
		txtUsername = new JTextField();
		txtUsername.setText("Username");
		txtUsername.setBounds(181, 98, 114, 19);
		add(txtUsername);
		txtUsername.setColumns(10);
		
		JLabel lblUsername = new JLabel("Username:");
		lblUsername.setBounds(103, 100, 89, 15);
		add(lblUsername);
		
		passwordField = new JPasswordField();
		passwordField.setBounds(181, 136, 114, 19);
		add(passwordField);
		
		JLabel lblPassword = new JLabel("Password:");
		lblPassword.setBounds(103, 138, 89, 15);
		add(lblPassword);
		
		JLabel lblWelcomeToThe = new JLabel("Welcome to the Georgia Tech Hospital Software System");
		lblWelcomeToThe.setBounds(32, 34, 406, 15);
		add(lblWelcomeToThe);
		
		setPreferredSize(new Dimension(450, 300));

	}
	

	/**
	 * returns the array of user data
	 * @return array containing user data
	 */
	public String[] getArr()
	{
		return this.arr;
	}
	
	/**
	 * setter for the array.
	 * @param array Array of user input data
	 */
	public void setArr(String[] array)
	{
		this.arr = array;
	}
	
	/**
	 * getter for the username textfield
	 * @return txtUsername
	 */
	public JTextField getTextfield()
	{
		return this.txtUsername;
	}
	
	/**
	 * getter for the password field
	 * @return passwordField
	 */
	public JPasswordField getPassfield()
	{
		return this.passwordField;
	}
	
	/**
	 * displays this panel
	 */
	public void display()
	{
		GUI_Main.replacePanel(this);
	}
	

	/**
	 * Private listener class for the register button
	 * @author SCIUUG Faults
	 *
	 */
	private class RegisterListener implements ActionListener{
		public void actionPerformed(ActionEvent event)
		{
			System.out.println("Register is pressed");
			GUI_Main.rpage = new RegistrationPanel();
			GUI_Main.rpage.setPrevious(GUI_Main.lpanel);
			GUI_Main.rpage.display();
			}
	}
	
	/**
	 * Private listener class for Login button
	 * @author SCIUUG Faults
	 *
	 */
	private class LoginListener implements ActionListener{

		public void actionPerformed(ActionEvent event)
		{
			String[] a = new String[2];
			                      
			a[0] = getTextfield().getText();
			a[1] = getPassfield().getText();
			
			setArr(a);
			GUI_Main.setPause(true);

		}
	}

}
